package Offer2017;

import java.util.Stack;

/**从尾到头打印链表
 * Created by 雷文康 on 2017/12/28.
 */
public class Test05 {
    public static void main(String[] args) {
        ListNode head = new ListNode(0);
        ListNode p1 = new ListNode(1);
        ListNode p2 = new ListNode(2);
        ListNode p3 = new ListNode(3);
        head.next = p1;
        p1.next = p2;
        p2.next = p3;
        printListNodeReversely(head);

    }

    public static void printListNodeReversely(ListNode head) {
        if (head == null) {
            return;
        }
        Stack<Integer> stack = new Stack<>();
        ListNode p = head;


        while (p != null) {
            stack.add(p.value);
            p = p.next;
        }
        while (!stack.isEmpty()) {
            System.out.println(stack.pop());
        }
    }
}
